package br.com.cadastro.hibernate.util;

import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;

public class HibernateUtil {

	private static SessionFactory factory = null;

	private static SessionFactory buildSessionFactory() throws RuntimeException {
		if(factory == null){
			try{
				// Create the SessionFactory from hibernate.cfg.xml
				factory =  new AnnotationConfiguration().configure().buildSessionFactory();
			}catch(Throwable e){
				throw new RuntimeException(e);
			}
		}
		return factory;

	}

	public static SessionFactory getSessionFactory() {
		return buildSessionFactory();
	}

}